#!/bin/bash

cd /home/zuwenqiang/Respo2/SimMed

export PYTHONPATH=$PWD:$PYTHONPATH

directory=Trade_off/1_table1/logs
if [ ! -d "$directory" ]; then
    mkdir -p "$directory"
    echo "Directory created: $directory"
else
    echo "Directory already exists: $directory"
fi

# 外层循环：改变 max_epochs
for max_epochs in 10 20 30 40; do
    echo "Running experiments with max_epochs=$max_epochs"
    
    i=0
    while [ $i -lt 3 ]; do
        i=$((i+1))
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --max_epochs $max_epochs --exp_num $i configs/full/ISIC/vit-base.py 2>> $directory/vit_unfrozen_epochs$max_epochs.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --max_epochs $max_epochs --exp_num $i configs/full/APTOS/vit-base.py 2>> $directory/vit_unfrozen_epochs$max_epochs.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --max_epochs $max_epochs --exp_num $i configs/full/chest/vit-base.py 2>> $directory/vit_unfrozen_epochs$max_epochs.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --max_epochs $max_epochs --exp_num $i configs/full/colon/vit-base.py 2>> $directory/vit_unfrozen_epochs$max_epochs.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --max_epochs $max_epochs --exp_num $i configs/full/endo/vit-base.py 2>> $directory/vit_unfrozen_epochs$max_epochs.log
    done
done


# 外层循环：改变 frozen_stages
for frozen_stages in 1 3 6 9; do
    echo "Running experiments with frozen_stages=$frozen_stages"
    
    i=0
    while [ $i -lt 3 ]; do
        i=$((i+1))
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --frozen_stages $frozen_stages --exp_num $i configs/full/ISIC/vit-base.py 2>> $directory/vit_frozen_stages$frozen_stages.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --frozen_stages $frozen_stages --exp_num $i configs/full/APTOS/vit-base.py 2>> $directory/vit_frozen_stages$frozen_stages.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --frozen_stages $frozen_stages --exp_num $i configs/full/chest/vit-base.py 2>> $directory/vit_frozen_stages$frozen_stages.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --frozen_stages $frozen_stages --exp_num $i configs/full/colon/vit-base.py 2>> $directory/vit_frozen_stages$frozen_stages.log
        CUDA_VISIBLE_DEVICES=4,5,6,7 python -m torch.distributed.launch --nnodes 1 --node_rank 0 --master_addr 127.0.0.1 --nproc_per_node 4 --master_port 16923 finetune_gpu.py --launcher pytorch --frozen_stages $frozen_stages --exp_num $i configs/full/endo/vit-base.py 2>> $directory/vit_frozen_stages$frozen_stages.log
    done
done